<?php
class Test extends IController
{
    public function index(){
        $this->redirect("login_di");
    }
    public function add_do(){
        $uname=IReq::get("uname");
        $dizi=IReq::get("dizi");
        $pass = IFilter::act(IReq::get("pass"),'int');
        $model = new IModel("testuser");
        // print_r($pass);
        $arr = array('uname'=>$uname,'pass'=>$pass,'dizi'=>$dizi);

        $model->setData($arr);
        $res = $model->add();
        // $res = $model->add();
        // $result = $model->add();
        if ($res) {
            $this->redirect("show");
        } else {
            $this->redirect("adds.html");
        }
        
    }
    public function show(){
        $model = new IModel("testuser");
        $res = $model->query();
        // echo $res;
        // var_dump($res);
        $this->setRenderData(['res'=>$res]);
        $this->redirect("show");
    }
    public function iptest(){
        // echo "<pre>";
        // print_r($_SERVER);
    }
    public function ajax(){
        echo "string";
        $address=$_POST['adds'];
        $ak="jBhtftnoivHwS5EypucQkZWaomEIuQcN";
        $url="http://api.map.baidu.com/geocoder/v2/?address=$address&output=json&ak=$ak";
        $data=file_get_contents($url);
        $data=json_decode($data,ture);
        $arr['lat']=$data['result']['location']['lat'];
        $arr['lng']=$data['result']['location']['lng'];
        // echo "<pre>";
        // print_r($data);
        echo json_decode($arr);
    }
    public function login_do(){
                $uname=IReq::get('uname');
                $pass=IReq::get('pass');
                $model=new IModel("testuser");
                $data=$model->query("uname='$uname' and pass = '$pass'");
                // print_r($data);die;
                if($data){
                    echo "登陆成功";
                    $_SESSION['uid']=$data[0]['id'];
                    // echo $_SESSION['uid'];die;
                    $this->redirect("show");
                }else{
                    echo "账户或密码有误";
                }
    }
    public function do_ss(){
        $this->redirect("qqlogin");
    }
    public function ditu_name(){
    	$this->redirect("login_id");
    }
    public function qq_login(){
        $appid='101353491';         // APPID
        //$appkey='df4e46ba7da52f787c6e3336d30526e4';         // APPKEY
        $redirect_uri='http://www.iwebshop.com/index.php';      // 回调地址
        $state=rand(1000,9000);
        $url="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=$appid&redirect_uri=$redirect_uri&state=$state";
        // echo $url;
        // print_r($url);
       //     http://graph.qq.com/demo/index.jsp?code=9A5F************************06AF&state=test
        header("Location:$url");
    }
}
?>